package com.class05.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class StudentDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void updateNameById(String name, Integer id) {
        String sql = "update students set name = ? where id = ? ;";
        int rows = jdbcTemplate.update(sql, name, id);
    }



//   配置事务为只读
//    @Transactional(readOnly = true)
    public void updateAgeById(Integer age, Integer id) {
        String sql = "update students set age = ? where id = ? ;";
        jdbcTemplate.update(sql, age, id);
    }
}
